Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug of connection event of gamepad at startup #730

Merged
merged 2 commits into from
Oct 29, 2020

Conversation

simpuid
Copy link
Contributor

@simpuid simpuid commented Oct 25, 2020

First commit removes the floating point equality comparison by modifying the filter function. Now filter function outputs Option<f32> instead of f32 and output is None when no change is required.

Second commit fixes the bug which makes it impossible to detect already connected gamepads at game startup. If you plug the gamepad first and then launches the game, connection event wouldn't occur. Removal of this code causes this bug.

To detect already connected gamepads' connection events at startup, a system must query for events at POST_STARTUP stage because bevy_gilrs generates raw events at PRE_STARTUP stage and bevy_input generates filtered events at STARTUP stage (it must execute after bevy_gilrs system).

@memoryruins memoryruins added the A-Input Player input via keyboard, mouse, gamepad, and more label Oct 25, 2020
@cart
Copy link
Member

cart commented Oct 28, 2020

If you plug the gamepad first and then launches the game, connection event wouldn't occur. Removal of this code causes this bug.

Haha oops. Thanks for catching this :)

use bevy_input::gamepad::{Gamepad, GamepadButton, GamepadEvent, GamepadEventType};
use bevy_utils::HashSet;

fn main() {
App::build()
.add_default_plugins()
.init_resource::<GamepadLobby>()
.add_startup_system(connection_system.system())
.add_startup_system_to_stage(POST_STARTUP, connection_system.system())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming you're adding this duplicate system here in case gamepad_system runs before connection system?

Could we just have a single add_system_to_stage(PRE_UPDATE, connection_system.system()) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.add_system_to_stage(stage::PRE_UPDATE, connection_system.system()) works fine (tested it too)

@cart cart merged commit fb2b19d into bevyengine:master Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants